package org.j2se.learn;

import java.util.Date;
import java.util.HashMap;
import java.util.TreeMap;

/**
 * User: 缪凯
 * Date: 12-1-10
 * Time: 下午2:33
 */
public class OrderMap {
    private TreeMap tree = new TreeMap();

    private HashMap hash = new HashMap();

    public void fallTreeMap(){
        for(int i = 0 ; i < 10000000 ; i++){
            tree.put(String.valueOf(i), i);
        }

    }

    public void fallHashMap(){
        for(int i = 0 ; i < 10000000 ; i++){
            hash.put(String.valueOf(i), i);
        }
    }

    public void findTreeValue(String key){
         System.out.println(this.tree.get(key));
    }

    public void findHashValue(String key){
         System.out.println(this.hash.get(key));
    }

    public static void main(String[] args){
        OrderMap o = new OrderMap();
//        System.out.println("Tree 开始" + new Date(System.currentTimeMillis()));
//        o.fallTreeMap();
//        System.out.println("Tree 结束" + new Date(System.currentTimeMillis()));
//        o.findTreeValue("1789234");
//        System.out.println("Tree 查找结束" + new Date(System.currentTimeMillis()));

        System.out.println("Hash 开始" + new Date(System.currentTimeMillis()));
        o.fallHashMap();
        System.out.println("Hash 结束" + new Date(System.currentTimeMillis()));
        o.findHashValue("3789234");
        System.out.println("Hash 查找结束" + new Date(System.currentTimeMillis()));
    }

}
